import 'dart:async';
import 'package:flutter/services.dart';
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
class SplashPage extends StatefulWidget {
  @override
  _SplashPageState createState() => _SplashPageState();
}

class _SplashPageState extends State<SplashPage> {
  StreamSubscription _subscription;
  @override
  void initState() {
    super.initState();
  }

  @override
  void dispose() {
    _subscription?.cancel();
    super.dispose();
  }



  _goHome() {
//    NavigatorUtils.push(context, Routes.home, replace: true);
  }


  Widget splashPage(context){
    return  Scaffold(
        body:Container(
          padding: EdgeInsets.only(top:100,left:50,right:50,bottom:50),
          height: double.infinity,
          child: Center(
            child: Column(
              children: <Widget>[
                Image.asset('assets/images/logo2.png'),
                Container(
                  margin: EdgeInsets.only(top:20,bottom:30),
                  child:Text('聚集集隐私政策',style: TextStyle(color:Colors.black,fontSize: 18)),
                ),
                RichText(
                  text: TextSpan(
                      style: TextStyle(color:Colors.black54),
                      text:'欢迎使用聚集集。您可使用本应用，进行商品浏览，支付购买，售后服务等功能。在使用过程中，本应用需要访问获取手机信息权限，用于获取IMEI,识别和区分不同用户。我们将严格准守相关法律和隐私政策以保护您的个人信息。请您阅读并同意',children: [
                    TextSpan(
                        text: '《用户协议》',
                        style: TextStyle(
                            color:Colors.blue
                        ), recognizer:
                    TapGestureRecognizer()..onTap = () async {
                      //这里做点击事件
//                      String url = 'https: //www.mi.com/about/user-agreement';
                    }
                    ),
                    TextSpan(
                        text: '、',
                        style: TextStyle(
                            color:Colors.black54
                        )
                    ),
                    TextSpan(
                        text: '《隐私政策》',
                        style: TextStyle(
                            color:Colors.blue
                        ), recognizer:
                    TapGestureRecognizer()..onTap = () async {
                      //这里做点击事件
//                      String url = 'https://www.mi.com/about/new-privacy';
//                      NavigatorUtils.goWebViewPage(context,'小米用隐私政策',url);
                    }
                    )
                  ]
                  ),
                ),
                Container(
                  margin: EdgeInsets.only(top:50,bottom:30),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: <Widget>[
                      OutlineButton(
                        onPressed: (){
                          showDialog(
                              context: context,
                              builder: (context) {
                                return AlertDialog(
//                                      contentPadding: EdgeInsets.all(100.0),
                                  title: Text('提示'),
                                  content: Text('你需要同意相关政策条款方可使用本软件'),
                                  actions: <Widget>[
                                    RaisedButton(
                                      textColor: Colors.white,
                                      color:Colors.grey,
                                      child: Text('不同意并退出',style:TextStyle(
                                          fontSize: 15
                                      )),onPressed: () {
                                      SystemChannels.platform.invokeMethod('SystemNavigator.pop');
                                    },),
                                    RaisedButton(
                                      color:Colors.red,
                                      child: Text('同意并进入软件'),
                                      onPressed: (){
                                        _goHome();
                                      },),
                                  ],
                                );
                              });
                        },
                        child: Text('不同意'),
                        textColor: Colors.black26,
                      ),
                      RaisedButton(
                        color:Colors.redAccent,
                        textColor: Colors.white,
                        onPressed: (){
                          _goHome();
                        },
                        child: Text('同意'),
                      )
                    ],
                  ),
                )

              ],
            ),
          ),
        )
    );
  }

  @override
  Widget build(BuildContext context) {
    return Material(
        child: splashPage(context)
    );
  }

//  @override
//  Widget build(BuildContext context) {
//    return Material(
//        color: ThemeUtils.getBackgroundColor(context),
//        child: _status == 0
//            ? FractionallyAlignedSizedBox(
//                heightFactor: 1,
//                widthFactor: 1,
//                leftFactor: 1,
//                bottomFactor: 0,
//                child: const LoadAssetImage('logo2'))
//            : Swiper(
//                key: const Key('swiper'),
//                itemCount: _guideList.length,
//                loop: false,
//                itemBuilder: (_, index) {
//                  return LoadAssetImage(
//                    _guideList[index],
//                    key: Key(_guideList[index]),
//                    fit: BoxFit.cover,
//                    width: double.infinity,
//                    height: double.infinity,
//                  );
//                },
//                onTap: (index) {
//                  if (index == _guideList.length - 1) {
//                    _goHome();
//                  }
//                },
//              ));
//  }
}
